package com.sm.imlibrary.model.http;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;

/**
 * created by zhud on 2019/8/7
 */
public class MessageBean implements Parcelable,Serializable {
    public Long id;
    //发送人
    public String from;
    //接受人
    public String to;
    //会话类型C2C
    public String chatType;
    //消息类型 Text/Image
    public String messageType;
    //消息内容 base64
    public String message;
    //是否已读
    public Integer isRead;
    //创建时间
    public Long createTime;

    public MessageBean() {
    }

    protected MessageBean(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readLong();
        }
        from = in.readString();
        to = in.readString();
        chatType = in.readString();
        messageType = in.readString();
        message = in.readString();
        if (in.readByte() == 0) {
            isRead = null;
        } else {
            isRead = in.readInt();
        }
        if (in.readByte() == 0) {
            createTime = null;
        } else {
            createTime = in.readLong();
        }
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(id);
        }
        dest.writeString(from);
        dest.writeString(to);
        dest.writeString(chatType);
        dest.writeString(messageType);
        dest.writeString(message);
        if (isRead == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(isRead);
        }
        if (createTime == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(createTime);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<MessageBean> CREATOR = new Creator<MessageBean>() {
        @Override
        public MessageBean createFromParcel(Parcel in) {
            return new MessageBean(in);
        }

        @Override
        public MessageBean[] newArray(int size) {
            return new MessageBean[size];
        }
    };
}
